﻿using BacklogParser.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace BacklogParser.Parsers
{
    public static class PriorityClaimParser
    {
        public static List<PriorityClaim> Parse(XElement claims)
        {
            var priorityClaims = claims.Descendants(Constants.Epo + "applicants").ToList();
            return ParsePriorityClaims(priorityClaims);
        }

        private static List<PriorityClaim> ParsePriorityClaims(List<XElement> priorityClaims)
        {
            var result = new List<PriorityClaim>();

            foreach (var item in priorityClaims)
            {
                var applicant = new PriorityClaim
                {
                    Date = item.Descendants(Constants.Epo + "date").First().Value,
                    Country = item.Descendants(Constants.Epo + "country").First().Value,
                    DocNumber = item.Descendants(Constants.Epo + "doc-number").First().Value,
                    Kind = item.Attribute("kind").Value,
                    Sequence = item.Attribute("sequence").Value
                };

                result.Add(applicant);
            }

            return result;
        }
    }
}
